package com.tjetc.service.impl;

import com.tjetc.entity.OrderShoes;
import com.tjetc.dao.OrderShoesDao;
import com.tjetc.entity.Orders;
import com.tjetc.service.OrderShoesService;
import com.tjetc.util.Pager;
import org.apache.catalina.User;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 订单鞋详细(OrderShoes)表服务实现类
 *
 * @author makejava
 * @since 2025-09-13 16:06:07
 */
@Service("orderShoesService")
public class OrderShoesServiceImpl implements OrderShoesService {
    @Resource
    private OrderShoesDao orderShoesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param osid 主键
     * @return 实例对象
     */
    @Override
    public OrderShoes queryById(Long osid) {
        return this.orderShoesDao.queryById(osid);
    }

    @Override
    public OrderShoes selectByOrderId(Long orderId) {
        return this.orderShoesDao.selectByOrderId(orderId);
    }




    @Override
    public Object selectByUserId( Long userId, Integer pageNum, Integer pageSize) {
        //查询总记录条数
        Integer recordCount = orderShoesDao.count(userId);
        //构建分页信息对象
        Pager pager = new Pager(pageNum, pageSize, recordCount);
        //根据pager查询需要的数据
        List<OrderShoes> list = orderShoesDao.selectByUserId(userId,pager.getStart(), pageSize);
        //将分页信息和查询到的数据一起返回到前端
        HashMap<String,Object> map = new HashMap<>();
        map.put("pager",pager);
        map.put("list",list);
        return map;
    }
    /**
     * 新增数据
     *
     * @param orderShoes 实例对象
     * @return 实例对象
     */
    @Override
    public OrderShoes insert(OrderShoes orderShoes) {
        this.orderShoesDao.insert(orderShoes);
        return orderShoes;
    }

    /**
     * 修改数据
     *
     * @param orderShoes 实例对象
     * @return 实例对象
     */
    @Override
    public OrderShoes update(OrderShoes orderShoes) {
        this.orderShoesDao.update(orderShoes);
        return this.queryById(orderShoes.getOsid());
    }

    /**
     * 通过主键删除数据
     *
     * @param osid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long osid) {
        return this.orderShoesDao.deleteById(osid) > 0;
    }
}
